<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    /**
     * ajax步骤：
    */
    //  1.创建一个请求实例 XMLHttpRequest
    var xhr = new XMLHttpRequest();
    // console.log(xhr)
    // 2.打开一个连接 open(method,url)
    // get post delete patch put options 
    xhr.open('get', 'http://121.199.0.35:8888/index/carousel/findAll');
    // 3.发送请求 
    xhr.send();
    // 4.监听响应
    xhr.onreadystatechange = function () {
      //  xhr.readyState ===4  表示请求完成 
      // xhr.status 请求成功 
      if (xhr.readyState === 4 && xhr.status === 200) {
        // console.log(JSON.parse(xhr.response),'获取响应')
        var res = JSON.parse(xhr.response);
        res.data.forEach(function (item) {
          // console.log(item,'33333');
          var div = document.createElement('div');
          div.innerHTML = item.name + item.introduce;
          var img = document.createElement('img');
          img.src = item.url;
          img.style.width = '150px';
          document.body.appendChild(div);
          document.body.appendChild(img);
        })
      }
    }
  </script>
</body>

</html>